<template>
<div class="marketing-box">
    <el-tabs v-model="activeTab">
      <el-tab-pane :label="$t('common.check_in')" name="signin"></el-tab-pane>
      <el-tab-pane :label="$t('common.points_mall')" name="points"></el-tab-pane>
      <el-tab-pane :label="$t('common.presale')" name="presale"></el-tab-pane>
      <el-tab-pane :label="$t('common.flash_sale')" name="seckill"></el-tab-pane>
      <el-tab-pane :label="$t('common.group_buying')" name="assemble"></el-tab-pane>
      <el-tab-pane :label="$t('common.bargain')" name="bargain"></el-tab-pane>
      <el-tab-pane :label="$t('common.preview')" name="preview"></el-tab-pane>
      <!--      <el-tab-pane label="邀请有礼" name="invitation"></el-tab-pane>-->
      <el-tab-pane :label="$t('common.coupon')" name="coupon"></el-tab-pane>
      <el-tab-pane :label="$t('common.distribution')" name="agent"></el-tab-pane>
      <el-tab-pane :label="$t('common.universal_form')" name="table"></el-tab-pane>
      <el-tab-pane :label="$t('common.lucky_spin')" name="lottery"></el-tab-pane>
      <el-tab-pane :label="$t('common.task_center')" name="task"></el-tab-pane>
    </el-tabs>
    <el-select
      v-model="activePage"
      :placeholder="$t('common.please_select')"
      class="percent-w100"
      @change="changeFunc"
      value-key="id"
    >
      <el-option
        v-for="(item, index) in pages"
        :key="index"
        :label="item.name"
        :value="item"
      ></el-option>
    </el-select>
  </div>
</template>

<script>
import LinkApi from "@/api/link.js";
export default {
  data() {
    return {
      /*tab切换选择中值*/
      activeTab: "coupon",
      /*页面数据*/
      pages: [],
      /*选中的值*/
      activePage: null,
      /*分销数据*/
      agentList: [{
        id: 0,
        url: "pages/agent/index/index",
        name: $t("common.distribution"),
        type: $t("common.marketing")
      }],
      seckillList: [{
        id: 0,
        url: "pages/plus/seckill/list/list",
        name: $t("common.flash_sale"),
        type: $t("common.marketing")
      }],
      /*签到数据*/
      signinList: [{
        id: 0,
        url: "pages/plus/signin/signin",
        name: $t("common.check_in"),
        type: $t("common.marketing")
      }],
      /*积分商城数据*/
      pointsList: [{
        id: 0,
        url: "pages/plus/points/list/list",
        name: $t("common.points_mall"),
        type: $t("common.marketing")
      }],
      /*秒杀数据*/
      presaleList: [{
        id: 0,
        url: "pages/plus/presale/list",
        name: $t("common.presale"),
        type: $t("common.marketing")
      }],
      /*拼团*/
      assembleList: [{
        id: 0,
        url: "pages/plus/assemble/list/list",
        name: $t("common.group_buying"),
        type: $t("common.marketing")
      }],
      /*砍价*/
      bargainList: [{
        id: 0,
        url: "pages/plus/bargain/list/list",
        name: $t("common.bargain"),
        type: $t("common.marketing")
      }],
      // 礼包购活动
      packageList: [],
      // 邀请有礼活动
      invitationList: [],
      /*优惠券*/
      couponList: [{
        id: 0,
        url: "pages/coupon/coupon",
        name: $t("common.coupon"),
        type: $t("common.marketing")
      }],
      /*幸运大转盘*/
      lotteryList: [{
        id: 0,
        url: "pages/plus/lottery/lottery",
        name: $t("common.lucky_spin"),
        type: $t("common.marketing")
      }],
      // 万能表单
      tableList: [],
      taskList: [{
        id: 0,
        url: "pages/task/index",
        name: $t("common.task_center"),
        type: $t("common.marketing")
      }],
      previewList: [{
        id: 0,
        url: "pages/plus/preview/list/index",
        name: $t("common.preview"),
        type: $t("common.marketing")
      }]
    };
  },
  watch: {
    activeTab: function (n, o) {
      let self = this;
      self.pages = [];
      if (n != o) {
        if (n == "signin") {
          self.pages = self.signinList;
        } else if (n == "points") {
          self.pages = self.pointsList;
        } else if (n == "presale") {
          self.pages = self.presaleList;
        } else if (n == "seckill") {
          self.pages = self.seckillList;
        } else if (n == "assemble") {
          self.pages = self.assembleList;
        } else if (n == "bargain") {
          self.pages = self.bargainList;
        } else if (n == "package") {
          self.pages = self.packageList;
        } else if (n == "invitation") {
          self.pages = self.invitationList;
        } else if (n == "coupon") {
          self.pages = self.couponList;
        } else if (n == "lottery") {
          self.pages = self.lotteryList;
        } else if (n == "table") {
          self.pages = self.tableList;
        } else if (n == "task") {
          self.pages = self.taskList;
        } else if (n == "agent") {
          self.pages = self.agentList;
        } else if (n == "preview") {
          self.pages = self.previewList;
        }
        self.autoSend();
      }
    }
  },
  created() {
    this.pages = this.couponList;
    this.autoSend();
    this.getData();
  },
  methods: {
    /*获取数据*/
    getData() {
      let self = this;
      LinkApi.getList({}, true).then(res => {
        self.packageList = res.data.packageList;
        self.invitationList = res.data.invitationList;
        self.tableList = res.data.tableList;
      }).catch(error => {});
    },
    /*自动发送*/
    autoSend() {
      if (this.pages.length > 0) {
        this.activePage = this.pages[0];
        this.changeFunc();
      }
    },
    /*选中的值*/
    changeFunc(e) {
      this.$emit("changeData", this.activePage);
    }
  }
};
</script>

